package com.dragon.modules.yuegou.enums.member;

import com.fasterxml.jackson.annotation.JsonCreator;

import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public enum MemberAttribute {
	
	/**
	 * 都未登陆过
	 */
	NEVCE_LOGIN(0, "都未登陆过"),
	/**
	 * 登陆过小程序
	 */
	LOGIN_XCX(1, "登陆过小程序"),
	
	/**
	 * APP和小程序都登陆过
	 */
	LOGIN_XCX_AND_APP(2,"APP和小程序都登陆过");

	/**
	 * 枚举标识
	 */
	private final Integer code;

	/**
	 * 别名
	 */
	private final String alias;

	private MemberAttribute(Integer code, String alias) {
		this.code = code;
		this.alias = alias;
	}
	
	public Integer getValue() {
		return code;
	}

	/**
	 * 枚举标识
	 * 
	 * @return code
	 */
	public Integer getCode() {
		return code;
	}

	/**
	 * 别名
	 * 
	 * @return alias
	 */
	public String getAlias() {
		return alias;
	}

	/**
	 * 把code转化为费用类型枚举
	 * 
	 * @param code 代码
	 * @return
	 */
	@JsonCreator
	public static MemberAttribute from(Integer code) {
		if (code == null) {
			return null;
		}
		return CODE_MAP.get(code);
	}

	/**
	 * Code Map for LiftType
	 */
	private static final Map<Integer, MemberAttribute> CODE_MAP = Stream.of(MemberAttribute.values())
			.collect(Collectors.toMap(MemberAttribute::getCode, e -> e));
}
